import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_view/flutter_swiper_view.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';
import 'package:pdf/base/MyScaffold.dart';
import 'package:pdf/widgets/MyImage.dart';

import '../../model/GuidePage.dart';
import '../../res.dart';
import '../../utils/Toast/MyTosat.dart';
import '../../utils/Tool/MyTools.dart';
import '../../utils/color/ColorUtils.dart';
import '../../widgets/TextView.dart';
import '../home/HomeTabBar.dart';

class GuidePage_ extends StatefulWidget {
  const GuidePage_({super.key});

  @override
  State<GuidePage_> createState() => _GuidePageState();
}

class _GuidePageState extends State<GuidePage_> {
  final GuidePageList = [
    GuidePage(
        "Your Mobile Office",
        "Work efficiently and edit easily anytime, anywhere",
        Res.guidepage_img_mobile3x),
    GuidePage(
        "All-in-one PDF Editing",
        "Comment, insert, sign, split, merge and more",
        Res.guidepage_img_edit3x),
    GuidePage(
        "Multi-format Convers",
        "Supports converting multiple formats to PDF and converting PDF to others",
        Res.guidepage_img_convert3x),
  ];

  int index_ = 0;
  String? first;
  bool OK = false;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      navBarHide: true,
      body: Column(
        children: [
          Expanded(
            child: Swiper(
              itemBuilder: (context, index) {
                return Container(
                  padding: const EdgeInsets.only(top: 90, left: 30, right: 30),
                  alignment: Alignment.center,
                  child: Column(
                    children: [
                      Image(
                        image: AssetImage(GuidePageList[index].img),
                        width: 200,
                        height: 200,
                      ),
                      TextView(
                        GuidePageList[index].title,
                        margin: const EdgeInsets.only(top: 32),
                        style: TextStyle(
                            color: rgba(48, 49, 51, 1),
                            fontSize: 24,
                            fontWeight: FontWeight.bold),
                        onclick: () {
                          // String? firsts = getFirst();
                          // print("============$firsts==========");
                          //MyToast().show(firsts!);
                        },
                      ),
                      TextView(
                        GuidePageList[index].content,
                        maxLines: 2,
                        textAlign: TextAlign.center,
                        alignment: Alignment.center,
                        margin: const EdgeInsets.only(top: 16),
                        style: TextStyle(
                          color: rgba(100, 101, 102, 1),
                          fontSize: 16,
                        ),
                        onclick: () {
                          Get.off(const HomeTabBar());
                        },
                      )
                    ],
                  ),
                );
              },
              itemCount: GuidePageList.length,
              loop: false,
              onIndexChanged: (index) {
                index_ = index;
                if (index_ == 2) {
                  OK = true;
                } else {
                  OK = false;
                }
                setState(() {});
              },
              // control: SwiperControl(color: rgba(255, 78, 77, 1)),
              pagination: SwiperPagination(
                  builder: DotSwiperPaginationBuilder(
                      color: rgba(230, 231, 235, 1),
                      activeColor: rgba(255, 78, 77, 1))),
              // control: const SwiperControl(),
            ),
          ),
          Visibility(
            visible: OK,
            maintainAnimation: true,
            maintainSize: true,
            maintainState: true,
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
              child: Container(
                alignment: Alignment.center,
                height: 48,
                decoration: BoxDecoration(color: rgba(255, 78, 77, 1), borderRadius: BorderRadius.circular(6)),
                child: TextView(
                  "trial".tr,
                  alignment: Alignment.center,
                  style: const TextStyle(color: Colors.white),
                  onclick: () {
                    Get.off(const HomeTabBar());
                  },
                ),
              ),
            ),
          )
        ],
      ),
    );
  }
}
